package com.android.launcher3;

import java.util.List;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.SystemClock;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Scroller;

public class AppShortcutZone extends LinearLayout implements DragSource,
		MenuItemView.UninstallableMarkerDrawParent {
	private View.OnClickListener mOnClickListener;
	private View.OnLongClickListener mOnLongClickListener;
	private Drawable mApplicationsDrawableEdit;
	private Drawable mApplicationsDrawableMenu;
	private Drawable mApplicationsDrawableNormal;
	private Drawable mBgDrawable;
	private Drawable mBgDrawable2;
	private IconCache mIconCache;
	private Interpolator mCloseInterpolator;
	private Interpolator mInterpolator;
	private Interpolator mOpenInterpolator;
	private Launcher mLauncher;
	private LayoutInflater mInflater;
	private Paint mPaint;
	private Rect mTmpRect;
	private View mApplicationsView;
	private Animate[] mChildAnimate;
	private View[] mVirtualView;
	private boolean mEnabledChildAnimation;
	private boolean mEnabledDrawing = true;
	private boolean mIsDrawBg;
	private float mAnimationFrom;
	private float mAnimationTo;
	private int mAnimationDuration;
	private int mAnimationState = ANIMATION_STATE_DONE;
	private int mChildHeight;
	private int mChildWidth;
	private final int mColumnCount;
	private Bitmap mDeleteIcon;
	private Bitmap mEditBg;
	private DragController mDragger;
	private int mDeleteIconRightOffset;
	private int mDeleteIconTopOffset;
	private int mEditIndex;
	private int mEditLeftOffset;
	private int mEditLeftOffset2;
	private int mEditTopOffset;
	private int mIconWidth;
	private int mItemGap1;
	private int mItemGap2;
	private int mLRPadding;
	private int mOldOrientation = -1;
	private int mOrientation = 1;
	private int mTopOffset;
	private long mAnimationStartTime;
	private long start;
	private static final int ANIMATION_STATE_STARTING = 1;
	private static final int ANIMATION_STATE_RUNNING = 2;
	private static final int ANIMATION_STATE_DONE = 3;
	private static final boolean DEBUG = false;
	private static final String TAG = "AppShortcutZone";

	/**
	 * Creates a new AppShortcutZone object.
	 * 
	 * @param paramContext
	 * @param attrs
	 */
	public AppShortcutZone(final Context context, final AttributeSet attrs) {
		super(context, attrs);

		Rect localRect = new Rect();
		this.mTmpRect = localRect;
		this.mEditIndex = -1;
		this.mOpenInterpolator = new PrematureLinearInterpolator();

		this.mCloseInterpolator = new LateStartLinearInterpolator();

		this.mInterpolator = this.mOpenInterpolator;
		this.mOnClickListener = new View.OnClickListener() {
			public void onClick(final View view) {
				Object localObject = view.getTag();

				if ((localObject != null)
						&& (localObject instanceof ApplicationInfo)) {
					ApplicationInfo localApplicationInfo = (ApplicationInfo) localObject;

					if (mLauncher.getMenuManager().getMode() == 2) {
						if (!localApplicationInfo.systemApp) {
							String str = localApplicationInfo.intent
									.getComponent().getPackageName();
							mLauncher.showDeleteApplication(str);
						}
					} else {
						mLauncher.startActivitySafely(
								localApplicationInfo.intent, null);
						return;
					}
				}
			}
		};
		this.mOnLongClickListener = new View.OnLongClickListener() {
			public boolean onLongClick(final View view) {
				LogUtils.d(TAG, "onLongClick");

				// Log.e(TAG, "onLongClick");
				if (!mLauncher.getMenuManager().isOpened()) {
					view.setHapticFeedbackEnabled(false);

					return true;
				}

				Object localObject = view.getTag();

				if ((localObject != null)
						&& (localObject instanceof ApplicationInfo)) {
					ApplicationInfo localApplicationInfo = (ApplicationInfo) localObject;

					if (mLauncher.getMenuManager().getMode() == 2) {
						DragController localDragController1 = AppShortcutZone.this.mDragger;
						AppShortcutZone localAppShortcutZone1 = AppShortcutZone.this;
						localDragController1.startDrag(view,
								localAppShortcutZone1, localApplicationInfo,
								DragController.DRAG_ACTION_MOVE);
					}
				}

				return true;
			}
		};

		int[] arrayOfInt = R.styleable.AppShortcutZone;
		TypedArray localTypedArray = context.obtainStyledAttributes(attrs,
				arrayOfInt, 0, 0);
		this.mColumnCount = localTypedArray.getInt(
				R.styleable.AppShortcutZone_iconColumnCount, 4);
		localTypedArray.recycle();

		if (this.mColumnCount < 1) {
			throw new IllegalStateException(
					"AppShortcutZone_iconColumnCount should be at least 1");
		}

		this.mVirtualView = new View[this.mColumnCount - 1];
		this.mChildAnimate = new Animate[this.mColumnCount];
		init(context);
	}

	/**
	 * 完整.
	 */
	public void changeApplicationsIcon() {
		MenuManager localMenuManager = this.mLauncher.getMenuManager();
		MenuItemView localMenuItemView = (MenuItemView) this.mApplicationsView;

		if (!localMenuManager.isOpened()) {
			Drawable localDrawable1 = this.mApplicationsDrawableNormal;
			localMenuItemView.setImageDrawable(localDrawable1);

			String str1 = getContext().getResources().getString(
					R.string.group_applications);
			localMenuItemView.setText(str1);

			return;
		} else {
			if (localMenuManager.getMode() != 2) {
				Drawable localDrawable2 = this.mApplicationsDrawableMenu;
				localMenuItemView.setImageDrawable(localDrawable2);

				String str2 = getContext().getResources().getString(
						R.string.homescreenedit_home);
				localMenuItemView.setText(str2);

				return;
			}

			Drawable localDrawable3 = this.mApplicationsDrawableEdit;
			localMenuItemView.setImageDrawable(localDrawable3);

			String str3 = getContext().getResources().getString(
					R.string.homescreenedit_home);
			localMenuItemView.setText(str3);
		}
	}

	/**
	 * 完整.
	 */
	public void clearApplications() {
		removeAllViews();

		for (View localView1 : this.mVirtualView) {
			addView(localView1);
		}

		View localView2 = this.mApplicationsView;
		addView(localView2);
	}

	/**
	 * 不完整 。
	 * 
	 * @param focused
	 * @param direction
	 */
	public boolean dispatchUnhandledMove(final View focused, final int direction) {
		LogUtils.d(TAG, "dispatchUnhandledMove");

		// MenuManager localMenuManager;
		// int i;
		// int j;
		//
		// if (this.mLauncher != null)
		// {
		// localMenuManager = this.mLauncher.getMenuManager();
		// if (localMenuManager.isOpened())
		// {
		// i = localMenuManager.getChildCount();
		// if (i <= 1)
		// break label206;
		// if (paramInt == FOCUS_LEFT)
		// {
		// if (localMenuManager.getWhichScreen() == 0)
		// localMenuManager.snapToScreen(-1);
		// j = 1;
		// }
		// }
		// }
		return true;
	}

	/**
	 * 有可能有问题 。
	 * 
	 * @param isDrawBg
	 * @param isOpen
	 */
	public void drawBg(final boolean isDrawBg, final boolean isOpen) {
		this.mIsDrawBg = isDrawBg;

		if (isOpen) {
			this.mAnimationDuration = 500;
			this.mAnimationStartTime = SystemClock.uptimeMillis();

			if (this.mIsDrawBg) {
				this.mAnimationState = ANIMATION_STATE_STARTING;
				this.mAnimationFrom = 0.0F;
				this.mAnimationTo = 1.0F;
				this.mInterpolator = this.mOpenInterpolator;
			} else {
				this.mAnimationState = ANIMATION_STATE_DONE;
			}
		} else {
			if (this.mIsDrawBg) {
				this.mAnimationState = ANIMATION_STATE_STARTING;
				this.mAnimationFrom = 1.0F;
				this.mAnimationTo = 0.0F;
				this.mInterpolator = this.mCloseInterpolator;
			} else {
				this.mAnimationState = ANIMATION_STATE_DONE;
			}
		}

		invalidate();
	}

	/**
	 * 完整
	 * 
	 * @param canvas
	 * @param drawingTime
	 */
	public void drawChildUninstallableMarker(final Canvas canvas,
			final View drawingTime) {
		LogUtils.d(TAG, "drawChildUninstallableMarker");

		// Log.e(TAG, "drawChildUninstalla bleMarker   111");
		if (this.mDeleteIcon != null) {
			Object localObject = drawingTime.getTag();

			if ((localObject != null)
					&& (localObject instanceof ApplicationInfo)
					&& (!((ApplicationInfo) localObject).systemApp)) {
				int i = 0;

				if (getOrientation() != HORIZONTAL) {
					i = this.mTopOffset;
				}

				Bitmap localBitmap = this.mDeleteIcon;
				int j = drawingTime.getWidth();
				int k = this.mDeleteIcon.getWidth();
				int m = j - k;
				int n = drawingTime.getWidth();
				int i1 = this.mIconWidth;
				int i2 = (n - i1) / 2;
				int i3 = this.mDeleteIconRightOffset;
				int i4 = i2 + i3;
				float f1 = m - i4;
				float f2 = this.mDeleteIconTopOffset + 0 - i;
				Paint localPaint = this.mPaint;
				canvas.drawBitmap(localBitmap, f1, f2, localPaint);
			}
		}
	}

	public View getApplicationsView() {
		return this.mApplicationsView;
	}

	public int getColumnCount() {
		return this.mColumnCount;
	}

	public int getEnabledChildCount() {
		int i = getChildCount();
		int j = 0;
		int k = 0;

		while (k < i) {
			if (getChildAt(k).getVisibility() != View.GONE) {
				j++;
			}
			k++;
		}

		return j;
	}

	/**
	 * 完整.
	 * 
	 * @return
	 */
	public int getVisibleChildCount() {
		int i = getChildCount();
		int j = 0;
		int k = 0;

		while (k < i) {
			if (getChildAt(k).getVisibility() == View.VISIBLE) {
				j++;
			}
			k++;
		}

		return j;
	}

	/**
	 * 完整.
	 */
	public void loadApplications() {

		// Log.e(TAG,"loadApplications");

		Cursor localCursor = LauncherModel.loadTopAppFromDatabase(getContext());

		if (localCursor == null) {
			return;
		}

		// DatabaseUtils.dumpCursor(localCursor);

		int i = localCursor.getCount();

		// Log.e(TAG,"getCount "+i);

		int j = this.mColumnCount - 1;
		int k = Math.min(i, j);
		localCursor.moveToFirst();

		int m = 0;
		Context localContext = getContext();

		while (m < k) {
			// Log.e(TAG,"m "+m);
			String str = localCursor.getString(1);

			ComponentName localComponentName = ComponentName
					.unflattenFromString(str);
			ApplicationInfo localApplicationInfo = getApplicationInfo(
					localContext, localComponentName);

			if (localApplicationInfo != null) {
				int n = localCursor.getInt(2);
				localApplicationInfo.topNum = n;
				localApplicationInfo.editTopNum = n;
				View localView = makeItemView(localApplicationInfo);
				if ((n >= 0) && (n < 3)) {
					int i2 = this.mColumnCount - 1;
					if (n < i2) {
						m = n;
					}
				}
				removeViewAt(m);
				addView(localView, m);
				// Log.e(TAG,"addView   "+m);

			} else {
				// Log.e(TAG,"localApplicationInfo ==  null");

			}
			localCursor.moveToNext();
			m++;
		}

		localCursor.close();

		// Log.e(TAG,"loadApplications took  "+(
		// System.currentTimeMillis()-start)+"ms");

	}

	public void onDropCompleted(final View target, final boolean success,
			final Object dragInfo) {
		LogUtils.d(TAG, "onDropCompleted");
		this.mLauncher.getMenuManager().onDropCompleted(target, success,
				dragInfo);
	}

	/**
	 * 完整.
	 * 
	 * @param paramMotionEvent
	 * 
	 * @return
	 */
	public boolean onInterceptTouchEvent(final MotionEvent paramMotionEvent) {
		LogUtils.d(TAG, "onInterceptTouchEvent");

		if (this.mLauncher.isAddWidgetState()) {
			return true;
		} else {
			return false;
		}
	}

	public void setBitmap(final Bitmap paramBitmap) {
		this.mDeleteIcon = paramBitmap;
	}

	public void setDragger(final DragController paramDragController) {
		this.mDragger = paramDragController;
	}

	public void setEditBg(final Bitmap paramBitmap) {
		this.mEditBg = paramBitmap;
	}

	public void setEditIndex(final int paramInt) {
		this.mEditIndex = paramInt;
	}

	public void setEnabledChildAnimation(final boolean paramBoolean) {
		this.mEnabledChildAnimation = paramBoolean;
	}

	public void setEnabledDrawing(final boolean paramBoolean) {
		this.mEnabledDrawing = paramBoolean;
	}

	/**
	 * 完整.
	 * 
	 * @param paramApplicationInfo
	 * @param index
	 */
	public void updateApplication(final ApplicationInfo paramApplicationInfo,
			final int index) {
		if (paramApplicationInfo == null) {
			return;
		} else {
			View localView1 = getChildAt(index);

			if ((localView1 == null) || (index >= 3)) {
				return;
			}

			int i = this.mColumnCount - 1;

			if (index >= i) {
				return;
			}

			Object localObject = localView1.getTag();

			if ((localObject != null)
					&& ((ApplicationInfo) localObject == paramApplicationInfo)) {
				return;
			}

			View localView2 = makeItemView(paramApplicationInfo);
			addItem(localView2, index);
		}
	}

	/**
	 * 完整.
	 */
	public void updateApplications() {
		Log.e(TAG, "updateApplications");
		clearApplications();
		loadApplications();
	}

	protected void dispatchDraw(final Canvas paramCanvas) {
		LogUtils.d(TAG, "dispatchDraw");

		// Log.e(TAG,"dispatchDraw");
		if (!this.mEnabledDrawing) {
			return;
		}

		if (this.mAnimationState == ANIMATION_STATE_STARTING) {
			// Log.e(TAG,"ANIMATION_STATE_STARTING  111111111111");
			this.mAnimationState = ANIMATION_STATE_RUNNING;
		}

		float f10;

		if (this.mAnimationState == ANIMATION_STATE_RUNNING) {
			long l1 = SystemClock.uptimeMillis();
			long l2 = this.mAnimationStartTime;
			float f1 = (float) (l1 - l2);
			float f2 = this.mAnimationDuration;
			float f3 = f1 / f2;

			// Log.e("f3",""+f3);
			if (f3 >= 1.0F) {
				this.mAnimationState = ANIMATION_STATE_DONE;

				if (this.mIsDrawBg) {
					this.mLauncher.getMenuManager().mMenuOpenAnimationListener
							.onAnimationEnd(null);
				}

				// invalidate();
			} else {
				float f5 = this.mInterpolator.getInterpolation(f3);
				float f6 = this.mAnimationFrom;
				float f7 = this.mAnimationTo;
				float f9 = (f7 - f6) * f5;
				f10 = f6 + f9;

				int k = (int) (255.0F * f10);
				mBgDrawable.setAlpha(k);

				if (getOrientation() != HORIZONTAL) {
					float f15 = getWidth();
					float f16 = 1.0F - f10;
					int i7 = (int) (f15 * f16);
					Drawable localDrawable4 = this.mBgDrawable;
					int i8 = getWidth() + i7;
					int i9 = getHeight();
					localDrawable4.setBounds(i7, 0, i8, i9);
					this.mBgDrawable.draw(paramCanvas);
				} else {
					float f11 = getHeight();
					float f12 = 1.0F - f10;
					int m = (int) (f11 * f12);
					int n = getWidth();
					int i1 = getHeight() + m;
					mBgDrawable.setBounds(0, m, n, i1);
					this.mBgDrawable.draw(paramCanvas);
				}

				if (this.mAnimationState != ANIMATION_STATE_DONE) {
					invalidate();
				}
			}
		}

		if (this.mAnimationState == ANIMATION_STATE_DONE) {
			View localView;
			if (mIsDrawBg) {
				// Log.e(TAG,"mIsDrawBg   "+ !mIsDrawBg);
				this.mBgDrawable.setAlpha(255);
				Drawable localDrawable5 = this.mBgDrawable;
				int i10 = getWidth();
				int i11 = getHeight();
				localDrawable5.setBounds(0, 0, i10, i11);
				this.mBgDrawable.draw(paramCanvas);
			} else {
				Drawable localDrawable1 = this.mBgDrawable2;
				int i = getWidth();
				int j = getHeight();
				localDrawable1.setBounds(0, 0, i, j);
				localDrawable1.draw(paramCanvas);
			}

			if ((this.mEditBg == null) || (this.mEditIndex == -1)) {
				super.dispatchDraw(paramCanvas);

				return;
			}

			int i2 = this.mEditIndex;
			localView = getChildAt(i2);

			if ((localView == null) || (localView.getTag() == null)
					|| (localView.getVisibility() == View.VISIBLE)) {
				super.dispatchDraw(paramCanvas);
				return;
			}

			if (getOrientation() == HORIZONTAL) {
				Bitmap localBitmap2 = this.mEditBg;
				int i12 = localView.getLeft();
				int i13 = this.mEditLeftOffset;
				float f17 = i12 + i13;
				int i14 = localView.getTop();
				int i15 = this.mTopOffset;
				float f18 = i14 - i15 + 1;
				Paint localPaint2 = this.mPaint;
				paramCanvas.drawBitmap(localBitmap2, f17, f18, localPaint2);
			} else {
				Bitmap localBitmap1 = this.mEditBg;
				int i3 = localView.getLeft();
				int i4 = this.mEditLeftOffset2;
				float f13 = i3 + i4;
				int i5 = localView.getTop();
				int i6 = this.mEditTopOffset;
				float f14 = i5 + i6 + 1;
				Paint localPaint1 = this.mPaint;
				paramCanvas.drawBitmap(localBitmap1, f13, f14, localPaint1);
			}
		}

		super.dispatchDraw(paramCanvas);
	}

	// 不完整
	protected boolean drawChild(final Canvas paramCanvas, final View paramView,
			final long paramLong) {
		LogUtils.d(TAG, "drawChild");

		if (this.mDeleteIcon != null) {
			if ((this.mEditBg != null) && (paramView.getTag() != null)) {
				if (getOrientation() == 0) {
					Bitmap localBitmap2 = this.mEditBg;
					int n = paramView.getLeft();
					int i1 = this.mEditLeftOffset;
					float f3 = n + i1;
					int i2 = paramView.getTop();
					int i3 = this.mTopOffset;
					float f4 = i2 - i3 + 1;
					Paint localPaint2 = this.mPaint;
					paramCanvas.drawBitmap(localBitmap2, f3, f4, localPaint2);
				} else {
					Bitmap localBitmap1 = this.mEditBg;
					int i = paramView.getLeft();
					int j = this.mEditLeftOffset2;
					float f1 = i + j;
					int k = paramView.getTop();
					int m = this.mEditTopOffset;
					float f2 = k + m + 1;
					Paint localPaint1 = this.mPaint;
					paramCanvas.drawBitmap(localBitmap1, f1, f2, localPaint1);
				}
			}
		}

		return super.drawChild(paramCanvas, paramView, paramLong);
	}

	protected void onLayout(final boolean changed, final int l, final int t,
			final int r, final int b) {
		LogUtils.d(TAG, "onLayout");
		int orientation = getOrientation();
		int childCount = getChildCount();

		int k = this.mLRPadding;
		int m = this.mTopOffset;
		int i1 = 0;

		if (orientation != LinearLayout.HORIZONTAL) {
			k = 0;
		}

		int enabled_count = getEnabledChildCount();
		Rect localRect = this.mTmpRect;
		View localView;
		int i9;
		int i10;

		if (orientation == LinearLayout.HORIZONTAL) {
			if (enabled_count > 0) {
				int i3 = this.mColumnCount;
				if (enabled_count < i3) {
					i1 = getItemGap(enabled_count);
					int i4 = getMeasuredWidth();
					int i5 = this.mChildWidth * enabled_count;
					int i6 = i4 - i5;
					int i7 = (enabled_count - 1) * i1;
					k = (i6 - i7) / 2;
				}
			}
			int i8 = 0;
			while (i8 < childCount) {
				localView = getChildAt(i8);

				if (localView.getVisibility() == View.GONE) {
					// Log.e(TAG,"View.GONE");
					i8++;
					continue;
				}

				i9 = localView.getMeasuredWidth();
				i10 = localView.getMeasuredHeight();
				localView.getHitRect(localRect);

				int i13 = i9 + i1;
				int i14 = k + i9;
				int i15 = m + i10;

				if ((localView.getVisibility() == View.VISIBLE)
						&& (!localRect.isEmpty())
						&& (this.mEnabledChildAnimation)) {
					localRect.set(k, m, i14, i15);
					k += i13;
					// Log.e(TAG+ "layout","LEFT "+k+" "+m+ " "+i14 +" "+i15);
					this.mChildAnimate[i8].start(localView, localRect);
					// Toast.makeText(this.mContext, "layout Animate 111  ",
					// Toast.LENGTH_SHORT).show();
				} else {
					// Toast.makeText(this.mContext, "layout 222",
					// Toast.LENGTH_SHORT).show();
					// Log.e(TAG+ "layout","LEFT "+k+" "+m+ " "+i14 +" "+i15);
					localView.layout(k, m - 10, i14, i15); // edit by zoufeng
															// m-10
					k += i13;
				}
				i8++;
			}
		} else {
			if (enabled_count > 0) {
				int i3 = this.mColumnCount;
				if (enabled_count < i3) {
					i1 = getItemGap(enabled_count);
					int i4 = getMeasuredHeight();
					int i5 = this.mChildHeight * enabled_count;
					int i6 = i4 - i5;
					int i7 = (enabled_count - 1) * i1;
					m = (i6 - i7) / 2;
				}
			}

			int i8 = 0;
			while (i8 < childCount) {
				localView = getChildAt(i8);
				if (localView.getVisibility() == View.GONE) {
					i8++;
					continue;
				}
				i9 = localView.getMeasuredWidth();
				i10 = localView.getMeasuredHeight();
				localView.getHitRect(localRect);

				int i13 = i9 + i1;
				int i14 = k + i9;
				int i15 = m + i10;

				if ((localView.getVisibility() == View.VISIBLE)
						&& (!localRect.isEmpty())
						&& (this.mEnabledChildAnimation)) {
					localRect.set(k, m, i14, i15);
					m += i13;
					// Log.e(TAG+ "layout","LEFT "+k+" "+m+ " "+i14 +" "+i15);
					this.mChildAnimate[i8].start(localView, localRect);
					// Toast.makeText(this.mContext, "layout Animate 111  ",
					// Toast.LENGTH_SHORT).show();
				} else {
					// Toast.makeText(this.mContext, "layout 222",
					// Toast.LENGTH_SHORT).show();
					// Log.e(TAG+ "layout","LEFT "+k+" "+m+ " "+i14 +" "+i15);
					localView.layout(k, m, i14, i15);
				}
				m += i13;
				i8++;
			}
		}
	}

	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		LogUtils.d(TAG, "onMeasure");
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);

		int width = View.MeasureSpec.getSize(widthMeasureSpec);
		int height = View.MeasureSpec.getSize(heightMeasureSpec);
		int k = getChildCount();
		int i1 = this.mColumnCount;

		if (getOrientation() == LinearLayout.HORIZONTAL) {
			int i2 = (width - this.mLRPadding * 2) / i1;
			this.mChildWidth = i2;
			widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(
					this.mChildWidth, MeasureSpec.EXACTLY);
			heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height,
					MeasureSpec.EXACTLY);
			for (int i = 0; i < k; i++) {
				getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
			}
		} else {
			int i4 = this.mColumnCount;
			int i5 = height / i4;
			int i6 = this.mTopOffset;
			int i7 = i5 - i6;
			this.mChildHeight = i7;
			this.mChildWidth = width;
			widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(
					this.mChildWidth, MeasureSpec.EXACTLY);
			heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(
					this.mChildHeight, MeasureSpec.EXACTLY);
			for (int i = 0; i < k; i++) {
				getChildAt(i).measure(widthMeasureSpec, heightMeasureSpec);
			}
		}
	}

	/**
	 * 完整.
	 * 
	 * @param view
	 * @param index
	 * 
	 * @return
	 */
	View addItem(final View view, final int index) {
		View localView = getChildAt(index);
		removeViewAt(index);
		addView(view, index);

		Object localObject = view.getTag();

		if (localObject != null) {
			ApplicationInfo localApplicationInfo = (ApplicationInfo) localObject;
			localApplicationInfo.editTopNum = index;
			localApplicationInfo.editPageNum = -1;
			localApplicationInfo.editCellNum = -1;
		}

		return localView;
	}

	/**
	 * 不完整 .
	 * 
	 * @param index
	 */
	void arrangeItem(final int index) {
		if (getChildAt(index).getTag() == null) {
			return;
		}

		int i = getChildCount();
		int j = -1;
		int k = index + 1;

		// label25: if (k < i)
		// {
		// if (getChildAt(k).getVisibility() != 0)
		// j = k;
		// }
		// else if (j == -1)
		// k = paramInt - 1;
		while (true) {
			if (k >= 0) {
				if (getChildAt(k).getVisibility() != View.VISIBLE) {
					j = k;
				}
			} else {
				if (j == -1) {
					break;
				}

				removeViewAt(j);

				View localView = this.mVirtualView[index];
				addView(localView, index);
				k = 0;

				while (k < i) {
					Object localObject = getChildAt(k).getTag();

					if ((localObject != null)
							&& (localObject instanceof ApplicationInfo)) {
						((ApplicationInfo) localObject).editTopNum = k;
					}

					k++;
				}

				break;

				// k += 1;
				// break label25;
			}

			k--;
		}
	}

	/**
	 * 完整.
	 * 
	 * @param v
	 * @param paramInt
	 */
	void changeItem(final View v, final int paramInt) {
		View localView1 = getChildAt(paramInt);

		if (localView1 == null) {
			return;
		} else {
			if (localView1.getTag() != null) {
				int i = removeItem(v);
				removeItem(localView1);
				addItem(localView1, i);
				addItem(v, paramInt);
			} else {
				removeItem(v);
				addItem(v, paramInt);
			}
		}
	}

	/**
	 * 不完整 。
	 * 
	 * @param x
	 * @param y
	 * 
	 * @return
	 */
	int getIndexOfCell(int x, final int y) {
		// Log.e(TAG,"x "+x+" y "+y);
		Rect localRect2 = new Rect();
		this.getHitRect(localRect2);

		if (localRect2.contains(x, y)) {
			int k = localRect2.left;
			x -= k;

			int i = x / (this.getWidth() / this.mColumnCount);

			if (i == this.mColumnCount - 1) {
				i--;
			}

			return i;
		}

		return -1;
	}

	/**
	 * 完整.
	 * 
	 * @param applicationInfo
	 * 
	 * @return
	 */
	View makeItemView(final ApplicationInfo applicationInfo) {
		Resources localResources = getResources();

		MenuItemView localMenuItemView = (MenuItemView) this.mInflater.inflate(
				R.layout.application_boxed_top, this, false);
		Bitmap localBitmap = applicationInfo.iconBitmap;

		if (localBitmap == null) {
			localBitmap = BitmapFactory.decodeResource(localResources,
					R.drawable.ic_launcher_application);
		}

		// localBitmap = BitmapFactory.decodeResource(localResources,
		// R.drawable.mainmenu_icon_browser_bg);

		// FastBitmapDrawable localFastBitmapDrawable = new FastBitmapDrawable(
		// localBitmap);

		ImageView i = ((ImageView) localMenuItemView.findViewById(R.id.icon));

		i.setImageBitmap(localBitmap);

		// localMenuItemView.setImageDrawable(localResources.getDrawable(R.drawable.mainmenu_icon_browser_bg));

		localMenuItemView.setText(applicationInfo.title);
		localMenuItemView.setFocusable(true);
		localMenuItemView.setOnClickListener(this.mOnClickListener);
		localMenuItemView.setOnLongClickListener(mOnLongClickListener);
		localMenuItemView.setTag(applicationInfo);
		return localMenuItemView;
	}

	/**
	 * 完整.
	 * 
	 * @param v
	 * @return
	 */
	int removeItem(final View v) {
		int i = getChildCount();
		int j = -1;
		int k = 0;

		while (true) {
			if (k < i) {
				if (getChildAt(k) == v) {
					j = k;
				}
			} else {
				if (j != -1) {
					removeViewAt(j);

					View localView = this.mVirtualView[j];
					addView(localView, j);
				}

				return j;
			}

			k++;
		}
	}

	void setLauncher(final Launcher paramLauncher) {
		this.mLauncher = paramLauncher;
	}

	/**
	 * 完整.
	 * 
	 * @param context
	 * @param componentName
	 * 
	 * @return
	 */
	private ApplicationInfo getApplicationInfo(final Context context,
			final ComponentName componentName) {
		ApplicationInfo localApplicationInfo = null;
		Intent localIntent1 = new Intent(Intent.ACTION_MAIN);
		localIntent1.addCategory(Intent.CATEGORY_LAUNCHER);
		localIntent1.setComponent(componentName);

		List<ResolveInfo> localList = context.getPackageManager()
				.queryIntentActivities(localIntent1, 0);

		if ((localList != null) && (localList.size() > 0)) {
			ResolveInfo localResolveInfo = (ResolveInfo) localList.get(0);
			localApplicationInfo = new ApplicationInfo(localResolveInfo,
					mIconCache);
		}

		return localApplicationInfo;
	}

	private int getItemGap(final int paramInt) {
		switch (paramInt) {
		case 3:
			return mItemGap2;
		case 2:
			return mItemGap1;

		default:
			return 0;
		}
	}

	/**
	 * 完整 .
	 * 
	 * @param context
	 */
	private void init(final Context context) {
		this.mInflater = LayoutInflater.from(context);
		this.mPaint = new Paint();
		// Log.e(TAG,"context  "+context.getClass().getName());

		this.mIconCache = ((Launcher) context).getIconCache();

		Resources localResources = getResources();
		this.mOrientation = localResources.getConfiguration().orientation;
		this.mChildHeight = localResources
				.getDimensionPixelSize(R.dimen.menu_top_item_height);
		this.mChildWidth = localResources
				.getDimensionPixelSize(R.dimen.menu_top_item_width);
		this.mTopOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_topapp_top_offset);
		this.mEditLeftOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_edit_left_offset);
		this.mEditLeftOffset2 = localResources
				.getDimensionPixelSize(R.dimen.menu_edit_left_offset2);
		this.mEditTopOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_edit_top_offset);
		this.mDeleteIconTopOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_delete_icon_top_offset);
		this.mDeleteIconRightOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_delete_icon_right_offset);
		this.mIconWidth = localResources
				.getDimensionPixelSize(R.dimen.menu_item_icon_width);
		this.mLRPadding = localResources
				.getDimensionPixelSize(R.dimen.menu_lr_padding);
		this.mItemGap1 = localResources
				.getDimensionPixelSize(R.dimen.menu_top_item_gap1);
		this.mItemGap2 = localResources
				.getDimensionPixelSize(R.dimen.menu_top_item_gap2);

		setClickable(true);
		this.mApplicationsDrawableNormal = localResources
				.getDrawable(R.drawable.mainmenu_icon_application);
		this.mApplicationsDrawableMenu = localResources
				.getDrawable(R.drawable.mainmenu_icon_home);
		this.mApplicationsDrawableEdit = this.mApplicationsDrawableMenu;

		int i9 = 0;
		int i10 = this.mColumnCount - 1;

		while (i9 < i10) {
			this.mVirtualView[i9] = new View(context);
			this.mVirtualView[i9].setVisibility(View.GONE);
			i9++;
		}

		this.mBgDrawable = localResources
				.getDrawable(R.drawable.homescreen_menu_shortcut_bg);
		this.mBgDrawable2 = localResources
				.getDrawable(R.drawable.homescreen_menu_mainmenu_bg);
		start = System.currentTimeMillis();
		initApplicationsView();
		loadApplications();
		setDrawingCacheEnabled(true);
		buildDrawingCache(true);

		i9 = 0;

		int i11 = this.mColumnCount;

		while (i9 < i11) {
			this.mChildAnimate[i9] = new Animate();
			i9++;
		}

	}

	/**
	 * 完整 .
	 */
	private void initApplicationsView() {
		View localView1 = this.mInflater.inflate(
				R.layout.application_boxed_top, this, false);
		MenuItemView localMenuItemView = (MenuItemView) localView1;
		localMenuItemView.setImageDrawable(this.mApplicationsDrawableNormal);

		localMenuItemView.setText(getContext().getResources().getString(
				R.string.group_applications));

		int i = localView1.getPaddingTop();
		int j = localView1.getPaddingLeft();
		int k = localView1.getPaddingBottom();
		int m = localView1.getPaddingRight();
		localMenuItemView.setBackgroundResource(R.drawable.grid_selector2);
		localMenuItemView.setPadding(j, i, m, k);
		localMenuItemView.setFocusable(true);

		localMenuItemView.setOnClickListener(new View.OnClickListener() {
			public void onClick(final View v) {
				mLauncher.closeOptionsMenu();

				MenuManager localMenuManager = mLauncher.getMenuManager();

				if (localMenuManager.isOpened()) {
					if (localMenuManager.getMode() == MenuManager.EDIT_MODE) {
						mLauncher.menusave();
						localMenuManager
								.setMode(MenuManager.LAUNCH_MODE_DEFAULT);
					}

					localMenuManager.animateClose();
				} else {
					localMenuManager.animateOpen();
				}
			}
		});

		this.mApplicationsView = localMenuItemView;

		for (i = 0; i < this.mColumnCount - 1; i++) {
			addView(this.mVirtualView[i]);
		}

		addView(this.mApplicationsView);
	}

	class Animate implements Runnable {
		private Rect mRect;
		private Scroller mScroller;
		private View mTargetView;

		/**
		 * Creates a new Animate object.
		 */
		Animate() {
			Rect localRect = new Rect();
			this.mRect = localRect;

			Context localContext = AppShortcutZone.this.getContext();
			DecelerateInterpolator localDecelerateInterpolator = new DecelerateInterpolator();
			Scroller localScroller = new Scroller(localContext,
					localDecelerateInterpolator);
			this.mScroller = localScroller;
		}

		public boolean isEnd() {
			if (!this.mScroller.computeScrollOffset()) {
				return true;
			} else {
				return false;
			}
		}

		public void run() {
			Scroller localScroller = this.mScroller;
			boolean bool1 = localScroller.computeScrollOffset();
			int i = localScroller.getCurrX();
			int j = localScroller.getCurrY();
			View localView = this.mTargetView;

			if (bool1) {
				int k = localView.getWidth() + i;
				int m = localView.getHeight() + j;
				localView.layout(i, j, k, m);
				AppShortcutZone.this.invalidate();
				AppShortcutZone.this.post(this);

				return;
			} else {
				int n = localView.getWidth() + i;
				int i1 = localView.getHeight() + j;
				localView.layout(i, j, n, i1);
				AppShortcutZone.this.invalidate();
			}
		}

		public void start(final View paramView, final Rect paramRect) {
			stop();
			this.mTargetView = paramView;

			Rect localRect = this.mRect;
			paramView.getHitRect(localRect);

			Scroller localScroller = this.mScroller;
			int i = localRect.left;
			int j = localRect.top;
			int k = paramRect.left;
			int m = localRect.left;
			int n = k - m;
			int i1 = paramRect.top;
			int i2 = localRect.top;
			int i3 = i1 - i2;
			localScroller.startScroll(i, j, n, i3, 500);
			AppShortcutZone.this.post(this);
		}

		public void stop() {
			AppShortcutZone.this.removeCallbacks(this);
		}
	}

	class LateStartLinearInterpolator implements Interpolator {
		private float mStartFactor = 0.0F;

		/**
		 * Creates a new LateStartLinearInterpolator object.
		 */
		public LateStartLinearInterpolator() {
			// if ((this$1 > 0.0F) && (this$1 < 1.0F))
			// this.mStartFactor = this$1;
		}

		public float getInterpolation(final float paramFloat) {
			float f1 = this.mStartFactor;
			float f2;

			if (paramFloat <= f1) {
				f2 = 0.0F;

				return f2;
			} else {
				float f3 = this.mStartFactor;
				float f4 = (paramFloat - f3) * 1.0F;
				float f5 = this.mStartFactor;
				float f6 = 1.0F - f5;
				float f7 = f4 / f6;

				return Math.min(f7, 1.0f);
			}
		}
	}

	class PrematureLinearInterpolator implements Interpolator {
		private float mPrematureFactor = 1.0F;

		/**
		 * Creates a new PrematureLinearInterpolator object.
		 */
		public PrematureLinearInterpolator() {
			// if ((this$1 > 0.0F) && (this$1 < 1.0F))
			// this.mPrematureFactor = this$1;
		}

		public float getInterpolation(final float paramFloat) {
			float f1 = paramFloat * 1.0F;
			float f2 = this.mPrematureFactor;
			float f3 = f1 / f2;

			if (f3 > 1.0F) {
				f3 = 1.0F;
			}

			return f3;
		}
	}
}
